package com.isoft.mapper;

import com.isoft.entity.DfmeCfleEntity;
import org.apache.ibatis.annotations.*;

@Mapper
public interface DfmeCfleMapper {

    @Insert("INSERT INTO MSG_META(SENDER, RECEIVER, SEQUENCE_NUMBER, DATE_TIME, MSG_TYPE, SUB_TYPE) " +
            "VALUES(" +
            "#{meta.sender,jdbcType=VARCHAR}, " +
            "#{meta.receiver,jdbcType=VARCHAR}, " +
            "#{meta.sequenceNumber,jdbcType=NUMERIC}, " +
            "TO_TIMESTAMP(#{meta.dateTime,jdbcType=VARCHAR}, 'yyyymmddhh24miss'), " +
            "#{meta.type,jdbcType=VARCHAR}, " +
            "#{meta.subType,jdbcType=VARCHAR})")
    @Options(useGeneratedKeys = true, keyProperty = "meta.msgId", keyColumn = "MSG_ID")
    void insertMeta(DfmeCfleEntity entity);

    // 修改为达梦兼容的插入方式
    @Insert({
            "<script>",
            "INSERT INTO AIRCRAFT(FLIGHT_ID, AIRCRAFT_TYPE, AIRCRAFT_NUMBER) ",
            "VALUES(",
            "  NULL, ",
            "  <if test='crft.aircraftType != null'>#{crft.aircraftType,jdbcType=VARCHAR}</if>",
            "  <if test='crft.aircraftType == null'>''</if>, ",
            "  <if test='crft.aircraftCode != null'>#{crft.aircraftCode,jdbcType=VARCHAR}</if>",
            "  <if test='crft.aircraftCode == null'>''</if>",
            ")",
            "</script>"
    })
    @SelectKey(statement = "SELECT IDENT_CURRENT('AIRCRAFT')", keyProperty = "aircraftId",
            before = false, resultType = Long.class)
    int insertAircraft(DfmeCfleEntity entity);
}